var app = getApp();

Page({
    data: {
        sign_up: [ {
            name: "姓名"
        }, {
            name: "手机号"
        } ]
    },
    onLoad: function(e) {
        var t = this;
        app.setNavigationBarColor(this), console.log(e), t.setData({
            options: e
        }), app.getUserInfo(function(e) {
            console.log(e), t.setData({
                user_id: e.id,
                openid: e.openid
            });
        }), t.refresh();
    },
    refresh: function(e) {
        var t = this;
        app.util.request({
            url: "entry/wxapp/GroupType",
            cachetime: "0",
            success: function(e) {
                console.log("分类列表", e), t.setData({
                    nav_array: e.data
                });
            }
        }), app.util.request({
            url: "entry/wxapp/GoodsInfo",
            cachetime: "0",
            data: {
                goods_id: t.data.options.id
            },
            success: function(e) {
                console.log("商品详情", e), t.setData({
                    goods: e.data.goods
                });
            }
        });
    },
    formSubmit: function(e) {
        wx.showLoading({
            title: "正在提交报名",
            mark: !0
        });
        var t = this;
        t.setData({
            place_num: 2,
            name: e.detail.value.name,
            tel: e.detail.value.tel
        });
        var a = t.data, o = a.goods, n = a.options, i = a.nav_array, s = a.user_id;
        for (var d in i) if (i[d].id == o.type_id) var r = i[d].name;
        if (1 == n.type) var c = o.dd_price; else c = o.pt_price;
        var l = c;
        1 == t.confirm_info() && app.util.request({
            url: "entry/wxapp/SaveGroupOrder",
            data: {
                user_id: s,
                goods_id: o.id,
                logo: o.logo,
                goods_name: o.name,
                goods_type: r,
                price: c,
                goods_num: 1,
                money: l,
                receive_name: e.detail.value.name,
                receive_tel: e.detail.value.tel,
                receive_address: o.address,
                type: a.options.type,
                pay_type: 1,
                kt_num: a.options.kt_num,
                group_id: n.group_id,
                dq_time: o.end_time,
                xf_time: o.xf_time,
                activity_type: o.activity_type,
                coordinates: o.coordinates
            },
            success: function(e) {
                console.log(e), console.log("确定调用"), t.pay(e.data, l);
            }
        });
    },
    confirm_info: function(e) {
        var t = this, a = t.data;
        if (console.log(a), null == a.name || "" == a.name) wx.showModal({
            title: "温馨提示",
            content: "请输入您的姓名"
        }), t.setData({
            place_num: 1
        }), wx.hideLoading(); else {
            if (null != a.tel && "" != a.tel) return !0;
            wx.showModal({
                title: "温馨提示",
                content: "请输入您的联系电话"
            }), t.setData({
                place_num: 1
            }), wx.hideLoading();
        }
    },
    pay: function(e, t) {
        var a = this;
        console.log("调用微信支付");
        var o = a.data.openid;
        app.util.request({
            url: "entry/wxapp/GroupPay",
            data: {
                order_id: e,
                money: t,
                openid: o
            },
            success: function(e) {
                console.log(e), wx.requestPayment({
                    timeStamp: e.data.timeStamp,
                    nonceStr: e.data.nonceStr,
                    package: e.data.package,
                    signType: e.data.signType,
                    paySign: e.data.paySign,
                    success: function(e) {
                        console.log(e), wx.hideLoading(), wx.showToast({
                            title: "支付成功"
                        }), setTimeout(function() {
                            a.setData({
                                place_num: 2
                            }), wx.navigateTo({
                                url: "index"
                            });
                        }, 1500);
                    },
                    fail: function(e) {
                        console.log(e), wx.showLoading({
                            title: "支付失败"
                        }), setTimeout(function() {
                            wx.hideLoading(), a.setData({
                                place_num: 2
                            }), wx.reLaunch({
                                url: "../index/index"
                            });
                        }, 1500);
                    }
                });
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {}
});